import store from '@/store';

export default {
	data() {
		return {
			// 默认的全局分享内容
			share: {
				title: '鞋服在线',
				path: ``, // 全局分享的路径，比如 首页
				imageUrl: '', // 全局分享的图片(可本地可网络)
				desc: '',
				content: ''
			}
		}
	},
	
	//监听用户点击页面内转发按钮--分享给朋友
	onShareAppMessage(res) {
		let localStorage = uni.getStorageSync('localStorage'),pages = getCurrentPages(),curPage = pages[pages.length - 1],
		path = curPage.$page.fullPath;
		if(path.includes('?') ){
			path = `/${curPage.$page.fullPath}&invite_id=${localStorage['user_id']}`;
		}else{
			path = `/${curPage.$page.fullPath}?invite_id=${localStorage['user_id']}`;
		}
		return {
			title: store.state.config.com_title || this.share.title,
			path,
			imageUrl: this.share.imageUrl,
			desc:  store.state.config.share_desc || this.share.desc,
			content: this.share.content,
			success(res) {
				uni.showToast({
					title: '分享成功'
				})
			},
			fail(res) {
				uni.showToast({
					title: '分享失败',
					icon: 'none'
				})
			}
		}
	},

	// 监听用户点击页面内转发按钮--分享到朋友圈
	onShareTimeline(res) {
		let localStorage = uni.getStorageSync('localStorage'),pages = getCurrentPages(),curPage = pages[pages.length - 1],
		path = curPage.$page.fullPath;
		if(path.includes('?') ){
			path = `/${curPage.$page.fullPath}&invite_id=${localStorage['user_id']}`;
		}else{
			path = `/${curPage.$page.fullPath}?invite_id=${localStorage['user_id']}`;
		}
		return {
			title: store.state.config.com_title || this.share.title,
			path,
			imageUrl: this.share.imageUrl,
			desc:  store.state.config.share_desc || this.share.desc,
			content: this.share.content,
			success(res) {
				uni.showToast({
					title: '分享成功'
				})
			},
			fail(res) {
				uni.showToast({
					title: '分享失败',
					icon: 'none'
				})
			}
		}
	},

	
}